package com.cn.yugan.Engine.Beans;

import com.cn.yugan.Cons.FFConstants;
import com.cn.yugan.Engine.Json.CommentItemJsonObj;

import java.util.ArrayList;
import java.util.List;


/**
 * 评论内容
 *
 * @author chengc
 * @ClassName: CommentObj
 * @Description: 维护一个多楼的列表, 维护一个把多楼按顺序显示到一起的链表
 * @date 2016-7-19 下午12:30:06
 */
public class CommentObj {
    /**
     * 楼的列表
     */
    private List<CommentFloor> floorList = new ArrayList<CommentFloor>();

    // /** 评论列表 */
    // LinkedList<Object> commentList = new LinkedList<Object>();

    /**
     * 添加一栋楼
     *
     * @param floor
     * @author chengc
     */
    public void addOneF(CommentFloor floor) {
        floorList.add(floor);
    }
   
    public List<CommentFloor> getFloorList() {
        return floorList;
    }
    
    public void addFloorList(List<CommentFloor> list) {
         floorList.addAll(list);
    }

    /**
     * listview用方法-根据第几个item获取评论中对应的楼对应的楼层
     *
     * @param index
     * @return
     * @author chengc
     */
    public CommentItemJsonObj getItem(int index) {
        CommentItemJsonObj resItem = null;
        for (int i = 0; i < floorList.size(); i++) {
            CommentFloor floor = floorList.get(i);
            resItem = floor.getFloor(index);
            if (resItem != null) {
                if (floor.getFloor(index+1)==null){
                    resItem.isBottomFloor=true;
                }else {
                    resItem.isBottomFloor=false;
                }
                break;
            } else {
                index = index - floor.getCurShowSize();
            }
        }
        return resItem;
    }

    /**
     * listview用方法-根据第几个item获取评论中对应的楼对应的楼层
     *
     * @param index
     * @return
     * @author chengc
     */
    public CommentFloor getFloorByIndex(int index) {
        CommentFloor resFloor = null;
        for (int i = 0; i < floorList.size(); i++) {
            CommentItemJsonObj resItem = null;
            resFloor = floorList.get(i);
            resItem = resFloor.getFloor(index);
            if (resItem != null) {
                break;
            } else {
                index = index - resFloor.getCurShowSize();
            }
        }
        return resFloor;
    }

    /**
     * 获取当前显示的楼层数(隐藏重复引用的)
     *
     * @return
     * @author chengc
     */
    public int getCurSize() {
        int size = 0;
        for (int i = 0; i < floorList.size(); i++) {
            size = size + floorList.get(i).getCurShowSize();
        }
        return size;
    }

    /**
     * 获取当前显示的列表项中的楼层的一些信息:
     * <p/>
     * [当前串的总数,当前列表项显示评论所在串的楼层数,当前层是否隐藏]
     *
     * @return
     * @author chengc
     */
    public int[] getFloorInfoByIndex(int index) {
        int sum = 0;
        int num = 0;
        int flagHiden = FFConstants.CommentHideFlag.noNeedBtn;
        int hideSum = 0;
        for (int i = 0; i < floorList.size(); i++) {
            CommentFloor floor = floorList.get(i);
            sum = floor.getFloorSum(index);
            if (sum != 0) {
                num = sum - index;
                if (num == floor.repeatIndex) {
                    hideSum = floor.getHideSum();
                    if (floor.flagHidenRepeat == true) {
                        flagHiden = FFConstants.CommentHideFlag.floorHide;
                    } else {
                        flagHiden = FFConstants.CommentHideFlag.floorShow;
                    }
                }
                break;
            } else {
                index = index - floor.getCurShowSize();
            }
        }
        // 是否隐藏当前层?
        int[] res = {sum, num, flagHiden, hideSum};
        return res;
    }
    // public List<Object> getCommentList() {
    // // if (commentList.size() == 0) {
    // commentList.clear();
    // for (CommentFloor floor : floorList) {
    // commentList.addAll(floor.getList());
    // }
    // // }
    // return commentList;
    // }
}
